package main

import (
	"github.com/jinzhu/gorm"
	_ "github.com/jinzhu/gorm/dialects/postgres"
	"log"
	"time"
)

type UsersInfo struct {
	gorm.Model
	Username		string		`json:"username" gorm:"column:username;unique"`
	OldPassword		string		`json:"old_password" gorm:"column:old_password"`
	NewPassword		string		`json:"new_password" gorm:"column:new_password"`
	UserToken		string		`json:"user_token" gorm:"column:usertoken"`
	TokenExpired	int			`json:"token_expired" gorm:"column:token_expired"`
}
// 通过构造UsersInfo方法，返回带模式的表
func (UsersInfo) TableName() string  {
	return "users.users_info"
}

func main() {
	db, err := gorm.Open("postgres", "host=127.0.0.1 port=5432 user=postgres dbname=postgres password=123456 sslmode=disable")
	if err != nil {
		log.Println(err)
	}
	defer db.Close()

	// 禁用复数形式
	db.SingularTable(true)
	db.AutoMigrate(&UsersInfo{})

	userInfo := UsersInfo{
		Username: "张三",
		NewPassword: "123456",
	}
	db.Create(&userInfo)
}
